package pl.javarsovia.javarsovia4android.domain;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mgrzechocinski
 * @since 2010-06-13
 */
public class Partner {

	private String name;
	private PartnerCategory category;
	private PartnerType type;
	private String logoUrl;
	private int logoResId;
	private String websiteUrl;
	private String note;

	public static Map<PartnerCategory, List<Partner>> groupByCategories(List<Partner> partnersToGroup) {
		Map<PartnerCategory, List<Partner>> partnersByCategories = new HashMap<PartnerCategory, List<Partner>>();
		for (Partner partner : partnersToGroup) {
			PartnerCategory partnerCategory = partner.getCategory();
			if (partnersByCategories.get(partnerCategory) == null) {
				partnersByCategories.put(partnerCategory, new ArrayList<Partner>());
			}
			partnersByCategories.get(partnerCategory).add(partner);
		}
		return partnersByCategories;
	}

	public static Map<PartnerType, List<Partner>> groupByTypes(List<Partner> partnersToGroup) {
		Map<PartnerType, List<Partner>> partnersByTypes = new HashMap<PartnerType, List<Partner>>();
		for (Partner partner : partnersToGroup) {
			PartnerType partnerType = partner.getType();
			if (partnersByTypes.get(partnerType) == null) {
				partnersByTypes.put(partnerType, new ArrayList<Partner>());
			}
			partnersByTypes.get(partnerType).add(partner);
		}
		return partnersByTypes;
	}

	public Partner name(String name) {
		this.name = name;
		return this;
	}

	public Partner category(String category) {
		try {
			this.category = PartnerCategory.valueOf(category);
		} catch (IllegalArgumentException e) {
			this.category = PartnerCategory.UNDEFINED;
		}
		return this;
	}

	public Partner type(String type) {
		this.type = PartnerType.valueOf(type);
		return this;
	}

	public Partner note(String note) {
		this.note = note;
		return this;
	}

	public Partner logoUrl(String logoUrl) {
		this.logoUrl = logoUrl;
		return this;
	}

	public Partner logoResId(int resId) {
		this.logoResId = resId;
		return this;
	}

	public int getLogoResId() {
		return logoResId;
	}

	public Partner websiteUrl(String websiteUrl) {
		this.websiteUrl = websiteUrl;
		return this;
	}

	public String getName() {
		return name;
	}

	public PartnerCategory getCategory() {
		return category;
	}

	public String getLogoUrl() {
		return logoUrl;
	}

	public String getWebsiteUrl() {
		return websiteUrl;
	}

	public PartnerType getType() {
		return type;
	}

	public String getNote() {
		return note;
	}
}
